<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, maximum-scale=1, user-scalable=no,viewport-fit=cover">
    <link href="css/common.css" rel="stylesheet">
    <style>
        .form-group{
            background: #fff;
            border-bottom: 2px solid #eee;
            height: 50px;
        }
        .form-text{
            display: inline-block;
            text-align:right;
            line-height: 50px;
        }
        .form-input{
            line-height: 30px;
            padding-left: 5px;
            border: 0px;
        }
    </style>
</head>
<body>
<div class="head-nav">
    <div class="nav-left" onclick="javascript:history.back(-1)"><img src="img/gua/u18.png"></div>
    <div class="nav-title">修改信息</div>
</div>
<div class="main">
    <div class="form-group">
        <label class="wd-30 form-text">真实姓名：</label>
        <span><input class="form-input" type="text" id="real_name" value=""></span>
    </div>
    <div class="form-group">
        <label class="wd-30 form-text">身份证号：</label>
        <span><input class="form-input" type="text" id="id_card" value=""></span>
    </div>
    <div class="form-group">
        <label class="wd-30 form-text">手机号码：</label>
        <span id="phoneNum"></span>
    </div>
    <div style="height: 10vw"></div>

    <div class="btn-line" id="editUser" style="display: none">修改信息</div>
    <div style="height: 6vw"></div>
    <div class="tips red">*信息用于兑领大奖和提现之用，请认真填写</div>
</div>


<script src="js/jquery-1.8.0.min.js"></script>
<script src="js/common.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>

<script type="application/javascript">
    $(function () {
        getopenid();
        loadInfo();
    });
    var openid;
    function getopenid() {
        openid = window.localStorage.getItem("openid");
        if(openid == null || openid == undefined || openid == '') {
            getCode();
        }
    }
    function getCode() {
        var code = Common.queryGetParam('code');
        if(code == null || code == undefined || code == '') {
            location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx95bdc635798fcfe4&redirect_uri="+window.location.href+"&response_type=code&scope=snsapi_base#wechat_redirect";
            return;
        }
        var paramStr = {};
        paramStr.code = code;
        var params = {};
        params.paramStr = JSON.stringify(paramStr);
        Common.ajaxWithParam("/fenful/api/v1/common/getWxUserOpenId", params, function(data) {
            openid = data.openid;
            window.localStorage.setItem("openid", data.openid);
        },false);
    }
    function loadInfo(){
        var paramStr = {};
        paramStr.wxOpenId = openid;
        var params = {};
        params.paramStr = JSON.stringify(paramStr);
        Common.ajaxWithParam("/fenful/api/v1/login/getUserByOpenId", params, function(data) {
            $("#real_name").val(data.real_name);
            $("#id_card").val(data.id_card);
            $("#phoneNum").text(data.phoneNum);
            if(data.real_name||data.id_card){
                $("#editUser").remove();
            }else{
                $("#editUser").show();
            }
        });
    }


    $("#editUser").on("click",function () {
        var real_name = $("#real_name").val();
        var id_card = $("#id_card").val();
        if(!real_name||!id_card){
            layer.msg("请将信息填写完整");
            return;
        }
        //身份证号码校验
        var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if(!regIdNo.test(id_card)){
            layer.msg("身份证号码有误");
            return;
        }
        layer.open({
            content: '确定提交吗？提交之后不可修改'
            , btn: ['确定', '取消']
            , yes: function (index, layero) {
                //按钮【按钮一】的回调
                var paramStr = {};
                paramStr.wxOpenId = openid;
                paramStr.real_name = real_name;
                paramStr.id_card = id_card;
                var params = {};
                params.paramStr = JSON.stringify(paramStr);
                Common.ajaxWithParam("/fenful/api/v1/login/editRealName", params, function(data) {
                    layer.msg("修改成功");
                    setTimeout("window.location.href='guaUserInfo.html'",1000);
                });
            }
        });

    });
</script>

</body>
</html>